<?php
namespace lianlianwechat;


use app\common\model\StoreLianlianTmp;
use lianlianwechat\lib\ToolServer;
use think\facade\Config;

class LianPayApi
{
    private $tools;
    public function __construct($type = 'app')
    {
        $this->tools = ToolServer::getInstance(Config::get('lianlianwechat.'), $type);
    }

    // 公众号支付
    public function wechatpay($data)
    {
        $res = ToolServer::buildRequestPara($data);
        $result = ToolServer::getHttpResponseJSON($res);
        return $result;
    }

    // app支付
    public function apppay($data, $uid)
    {
        //业务来源。10 - APP。 13 - PC。16 - H5。18 - IVR。
        $tmp = StoreLianlianTmp::getByMid($uid);
        $risk_item = [
            'frms_ware_category' => $tmp['frms_ware_category'],
            'user_info_mercht_userno' => $tmp['user_id'],
            'user_info_dt_register' => $tmp['user_info_dt_register'],
            'delivery_addr_province' => $tmp['province_code'],
            'delivery_addr_city' => $tmp['city_code'],
            'delivery_phone' => $tmp['phone'],
            'user_info_bind_phone' => $tmp['phone'],
            'delivery_full_name' => $tmp['delivery_full_name'],
            'logistics_mode' => 2,
            'delivery_cycle'  => '72h',
            'goods_count' => '1',
            'goods_name' => '口红',
            'virtual_goods_status' => '0',
            'frms_client_chnl' => '10',
            'frms_ip_addr' => request()->ip()
        ];
        $data['risk_item'] = json_encode($risk_item);
        $res = ToolServer::buildRequestPara($data);
        $result = ToolServer::getHttpResponseJSON($res);
        return $result;
    }

    public function notify()
    {
//        $arr = array (
//            'bank_code' => '01020000',
//            'dt_order' => '20181205095955',
//            'money_order' => '0.01',
//            'no_order' => 'sc_20181205952130',
//            'oid_partner' => '201811300002302012',
//            'oid_paybill' => '2018120501472376',
//            'pay_type' => '2',
//            'result_pay' => 'SUCCESS',
//            'settle_date' => '20181205',
//            'sign' => 'EbSkBmrAs26ywLPwQ/274NvksU47HKpbmNHXzJtCnPGVIriPhrBDYSqMOfzxoo8q5mLaj2jsneDHenWVtKsKNi+jeeI8p9RJ47TK7dafmr4UH2c/R5EWzI7Fp6s8EUMkdjeyIIIipQmotWo6HCRP2dVgKihEYZ3Y1ZASIyCqU9w=',
//            'sign_type' => 'RSA',
//        );
//        $res = ToolServer::checkSgin($arr);
//        print_r($res);die;

    }
}